import os
import re
import string

def get_file_extension(filename):
    fileName, fileExtension = os.path.splitext(filename)
    return fileExtension


def extract_mail_address(sender):
	start, end = re.search('[^<]+@[^>]+', sender).span()
	return sender[start:end]


def has_match(string, patterns):
	return any([re.search(pattern, string) 
			for pattern in patterns])


def receiver_to_directory(receiver):
	start, end = re.search('[^@]+', receiver).span()
	coded_dir = receiver[start : end]

	if ((coded_dir[0] != '#') or (coded_dir == "#common#")):
		return ""

	return string.replace(coded_dir, "#", "/")	
